AWSコンソール設定をUI.Visionで自動化してみた

AWSコンソール設定をUI.Visionで自動化してみた

Clock Icon2024.06.11

こんにちは。たかやまです。

AWSコンソールでは以下のようにユーザ毎のカスタマイズが可能です。

AWS Management Console の設定 - AWS Management Console

ただ、こちらの設定はIAMユーザ/ロール毎に設定する必要があり、別のIAMユーザ/ロールにログインする場合別途設定を行う必要があります。

また、こちらのAWSコンソール設定について現状API操作や設定のインポート機能はないため、都度コンソールからポチポチ手動で設定する必要があります。

業務上、複数のIAMユーザ/ロールでAWSコンソールを使う場合、毎回設定を行うのは手間がかかるため、自動化したいと考えました。

そこで今回はRPAツールのUI.Visionを使いAWSコンソール設定を自動化してみたので、その内容をお伝えします。

とりあえずやってみたい方へ

とりあえずやってみたい方向けに、実際に使ってみた映像とソースコードになります。

こちらが実際に自動設定してみた映像です。

UI.Visionのソースコードは以下の通りです。

{
  "Name": "AWS Console Settings",
  "CreationDate": "2024-6-10",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://ap-northeast-1.console.aws.amazon.com/settings/home?region=ap-northeast-1",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "comment",
      "Target": "click // //button[contains(@class, 'awsui_button') and contains(@class, 'awsui_variant-primary')]",
      "Value": "",
      "Description": "リセット操作"
    },
    {
      "Command": "clickAndWait",
      "Target": "//button[@data-testid='reset-all-settings-modal-submit']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": "https://ap-northeast-1.console.aws.amazon.com/settings/display/edit?region=ap-northeast-1",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=theme-selector-light-theme-option",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=favorite-service-display-service-icon-only",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=favorites-bar-icon-size-large",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='submit-button']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": "https://ap-northeast-1.console.aws.amazon.com/settings/localization/edit",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=formField:r7:",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=option-list:r9:-option-6",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=formField:rj:",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=option-list:rl:-option-10",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "clickAndWait",
      "Target": "//button[@data-testid='submit-button']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": "https://ap-northeast-1.console.aws.amazon.com/console/home?region=ap-northeast-1",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "ec2",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-ec2']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "ecs",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-ecs']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "rds",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-rds']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "cloudformation",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-cfo']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "cloudwatch",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-cw']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "s3",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-s3']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "security hub",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-securityhub']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "guardduty",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-guardduty']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "detective",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-detective']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//*[@id='aws-unified-search-container']/div/div[1]/button",
      "Value": "",
      "Description": ""
    }
  ]
}

リセット操作の部分については、設定済みの内容が消されるため上記コード内ではコメントアウト処理をしています。

リセット操作については必要に応じてワークフローに組み込んでください。

UI.Visionとは

UI.Visionは、オープンソースのRPA(Robotic Process Automation)ツールで、ブラウザ上での操作を自動化するためのツールです。

対応OSとブラウザは以下の通りです。

  • OS : Windows, macOS, Linux
  • ブラウザ : Chrome, Firefox, Edge

ブラウザの自動ツールで有名なものとしては、Seleniumがあると思います。

Seleniumブラウザー自動化プロジェクト | Selenium

今回自動化を検討する上で、簡単なブラウザ操作をするのが目的なためローカル環境でコードを用意するというよりかは、ブラウザの拡張機能で完結するものを探していました。

Seleniumでもブラウザ拡張機能で利用できるSelenium IDEが提供されていますが更新が止まっていたり、UI.Vision自体がSelenium IDE互換の機能を提供しているため今回はUI.Visionを選択しました。

やってみる

UI.Visionのインストール

各ブラウザの拡張機能ストアからUI.Visionをインストールします。今回はGoogle Chromeを使ってUI.Visionをインストールします。

インストールが完了すると、ブラウザの右上の拡張機能アイコンからUI.Visionを起動できます。

起動するとUI.Visionのコンソールが別ウィンドウで起動されます。

UI.Visionの使い方

初期状態で以下のように Demo フォルダが用意されており、すぐにデモを実行することができます。

XModules フォルダには、UI.Visionの拡張モジュール(XModules)を利用するデモが用意されています。

XModulesは、マウスクリックイベントやキーボードショートカット、OCR、画像認識などの拡張機能を提供しています。

今回は、AWSコンソールの設定を自動化でXModulesを利用しませんが、X(例:XClickXMove ...)のつくCommandを利用したい場合には事前にXModulesをインストールしておく必要があります。

一番簡単な使い方は、実際の操作を Record で記録し、それを再生することです。

まず、はじめに + Macro をクリックして新しいマクロを作成します。

マクロを作成したら、右上の Record ボタンをクリックし、Recording状態になった後コンソールの操作を記録します。

Recordを開始した段階では、そのページを起動するOpenコマンドが記録されます。

操作が落ち着いたら、Stop Record ボタンをクリックしてRecordingを終了します。

操作した内容が以下のように記録されます。

記録した操作は Play Macro ボタンをクリックすることで再生することができます。

ただ、やってみていただくとわかりますが、記録されたコードはうまく動作しないことが多いです。

記録したマクロコード
{
  "Name": "Takayama Test",
  "CreationDate": "2024-6-11",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://ap-northeast-1.console.aws.amazon.com/settings/home?region=ap-northeast-1",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//*[@id=\":r7:\"]/div/div/div/div[2]/button/span",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\":r7:\"]/div/div/div/div[2]/button/span",
        "xpath=//div[2]/div/div/div/div/div/div/div/div[2]/button/span",
        "css=#:r7: > div.awsui_header_14iqq_1k7b2_255.awsui_remove-high-contrast-header_14iqq_1k7b2_382.awsui_with-paddings_14iqq_1k7b2_295 > div > div > div.awsui_actions_2qdw9_1i8z6_178.awsui_actions-variant-h2_2qdw9_1i8z6_190.awsui_actions-centered_2qdw9_1i8z6_183 > button > span"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=formField:r15:",
      "Value": "",
      "Targets": [
        "id=formField:r15:",
        "xpath=//*[@id=\"formField:r15:\"]",
        "xpath=//button[@id='formField:r15:']",
        "xpath=//div[2]/div/div/div/div/div/div/div/button",
        "css=#formField:r15:"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=formField:r1h:",
      "Value": "",
      "Targets": [
        "id=formField:r1h:",
        "xpath=//*[@id=\"formField:r1h:\"]",
        "xpath=//button[@id='formField:r1h:']",
        "xpath=//div[3]/div/div/div/div/div/div/div/button",
        "css=#formField:r1h:"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=formField:r1h:",
      "Value": "",
      "Targets": [
        "id=formField:r1h:",
        "xpath=//*[@id=\"formField:r1h:\"]",
        "xpath=//button[@id='formField:r1h:']",
        "xpath=//div[3]/div/div/div/div/div/div/div/button",
        "css=#formField:r1h:"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=formField:r1h:",
      "Value": "",
      "Targets": [
        "id=formField:r1h:",
        "xpath=//*[@id=\"formField:r1h:\"]",
        "xpath=//button[@id='formField:r1h:']",
        "xpath=//div[3]/div/div/div/div/div/div/div/button",
        "css=#formField:r1h:"
      ],
      "Description": ""
    },
    {
      "Command": "clickAndWait",
      "Target": "xpath=//*[@id=\"view-awsc-app-shell-awsc-app-shell__age_ontent-0\"]/div/div[2]/div/div[2]/div/div/div/div[2]/button/span",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\"view-awsc-app-shell-awsc-app-shell__age_ontent-0\"]/div/div[2]/div/div[2]/div/div/div/div[2]/button/span",
        "xpath=//div[2]/div/div/div/div[2]/button/span",
        "css=#view-awsc-app-shell-awsc-app-shell__age_ontent-0 > div > div:nth-child(2) > div > div.awsui_footer_1i0s3_1krki_140 > div > div > div > div:nth-child(2) > button > span"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//*[@id=\":rc:\"]/div/div/div/div[2]/button/span",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\":rc:\"]/div/div/div/div[2]/button/span",
        "xpath=//div[2]/div/div/div/div/div/div[2]/button/span",
        "css=#:rc: > div.awsui_header_14iqq_1k7b2_255.awsui_remove-high-contrast-header_14iqq_1k7b2_382.awsui_with-paddings_14iqq_1k7b2_295 > div > div > div.awsui_actions_2qdw9_1i8z6_178.awsui_actions-variant-h2_2qdw9_1i8z6_190.awsui_actions-centered_2qdw9_1i8z6_183 > button > span"
      ],
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=theme-selector-dark-theme-option",
      "Value": "dark",
      "Targets": [
        "id=theme-selector-dark-theme-option",
        "name=theme",
        "xpath=//*[@id=\"theme-selector-dark-theme-option\"]",
        "xpath=//input[@id='theme-selector-dark-theme-option']",
        "xpath=//div[3]/div/div/div/div/div/span[3]/span/span/input",
        "css=#theme-selector-dark-theme-option"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=theme-selector-dark-theme-option",
      "Value": "",
      "Targets": [
        "id=theme-selector-dark-theme-option",
        "name=theme",
        "xpath=//*[@id=\"theme-selector-dark-theme-option\"]",
        "xpath=//input[@id='theme-selector-dark-theme-option']",
        "xpath=//div[3]/div/div/div/div/div/span[3]/span/span/input",
        "css=#theme-selector-dark-theme-option"
      ],
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=theme-selector-light-theme-option",
      "Value": "light",
      "Targets": [
        "id=theme-selector-light-theme-option",
        "name=theme",
        "xpath=//*[@id=\"theme-selector-light-theme-option\"]",
        "xpath=//input[@id='theme-selector-light-theme-option']",
        "xpath=//div[3]/div/div/div/div/div/span[2]/span/span/input",
        "css=#theme-selector-light-theme-option"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=theme-selector-light-theme-option",
      "Value": "",
      "Targets": [
        "id=theme-selector-light-theme-option",
        "name=theme",
        "xpath=//*[@id=\"theme-selector-light-theme-option\"]",
        "xpath=//input[@id='theme-selector-light-theme-option']",
        "xpath=//div[3]/div/div/div/div/div/span[2]/span/span/input",
        "css=#theme-selector-light-theme-option"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=favorite-service-display-service-icon-only-label",
      "Value": "",
      "Targets": [
        "id=favorite-service-display-service-icon-only-label",
        "xpath=//*[@id=\"favorite-service-display-service-icon-only-label\"]",
        "xpath=//span[@id='favorite-service-display-service-icon-only-label']",
        "xpath=//div[2]/div/div[3]/div/div/div/div/div/span[2]/span/span[2]/span",
        "css=#favorite-service-display-service-icon-only-label"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//*[@id=\"view-awsc-app-shell-awsc-app-shell__age_ontent-0\"]/div/div[2]/div/div/div/div/div[2]/div/div/div/div[2]/button/span",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\"view-awsc-app-shell-awsc-app-shell__age_ontent-0\"]/div/div[2]/div/div/div/div/div[2]/div/div/div/div[2]/button/span",
        "xpath=//div[2]/div/div/div/div[2]/button/span",
        "css=#view-awsc-app-shell-awsc-app-shell__age_ontent-0 > div > div:nth-child(2) > div > div.awsui_grid-column_14yj0_o8rqb_137.awsui_colspan-3_14yj0_o8rqb_168 > div > div > div.awsui_footer_1i0s3_1krki_140 > div > div > div > div:nth-child(2) > button > span"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//*[@id=\":r4i:\"]/div/div/div/div[2]/button/span",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\":r4i:\"]/div/div/div/div[2]/button/span",
        "xpath=//div[3]/div/div/div/div/div/div[2]/button/span",
        "css=#:r4i: > div.awsui_header_14iqq_1k7b2_255.awsui_remove-high-contrast-header_14iqq_1k7b2_382.awsui_with-paddings_14iqq_1k7b2_295 > div > div > div.awsui_actions_2qdw9_1i8z6_178.awsui_actions-variant-h2_2qdw9_1i8z6_190.awsui_actions-centered_2qdw9_1i8z6_183 > button > span"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//*[@id=\"settingManagementForm\"]/div[2]/div/div/div/div[2]/button/span",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\"settingManagementForm\"]/div[2]/div/div/div/div[2]/button/span",
        "xpath=//div[2]/div/div/div/div[2]/button/span",
        "css=#settingManagementForm > div.awsui_footer_1i0s3_1krki_140 > div > div > div > div:nth-child(2) > button > span"
      ],
      "Description": ""
    },
    {
      "Command": "clickAndWait",
      "Target": "id=nav-home-link",
      "Value": "",
      "Targets": [
        "id=nav-home-link",
        "xpath=//*[@id=\"nav-home-link\"]",
        "xpath=//a[@id='nav-home-link']",
        "xpath=//div/a",
        "css=#nav-home-link"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=awsc-concierge-input",
      "Value": "",
      "Targets": [
        "id=awsc-concierge-input",
        "xpath=//*[@id=\"awsc-concierge-input\"]",
        "xpath=//input[@id='awsc-concierge-input']",
        "xpath=//input[2]",
        "css=#awsc-concierge-input"
      ],
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "ec2",
      "Targets": [
        "id=awsc-concierge-input",
        "xpath=//*[@id=\"awsc-concierge-input\"]",
        "xpath=//input[@id='awsc-concierge-input']",
        "xpath=//input[2]",
        "css=#awsc-concierge-input"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//*[@id=\"aws-unified-search-container\"]/div/div[3]/div/div/div[2]/div/div[2]/ul/li/div/div/ol/li/div/div/div[2]/div/h3/span/button",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\"aws-unified-search-container\"]/div/div[3]/div/div/div[2]/div/div[2]/ul/li/div/div/ol/li/div/div/div[2]/div/h3/span/button",
        "xpath=//span/button",
        "css=#aws-unified-search-container > div > div.search-6256.search-6257 > div > div > div.search-6241 > div > div.search-62102 > ul > li.search-62104.search-62205.search-62108 > div > div:nth-child(1) > ol > li:nth-child(1) > div > div.search-62122 > div.search-62127 > div > h3 > span > button"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//*[@id=\"app\"]/div/div/div/main/div/div[2]/div",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\"app\"]/div/div/div/main/div/div[2]/div",
        "xpath=//main/div/div[2]/div",
        "css=#app > div > div > div > main > div > div.awsui_content-wrapper_zycdx_1sc8d_103 > div"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=awsc-concierge-input",
      "Value": "",
      "Targets": [
        "id=awsc-concierge-input",
        "xpath=//*[@id=\"awsc-concierge-input\"]",
        "xpath=//input[@id='awsc-concierge-input']",
        "xpath=//input[2]",
        "css=#awsc-concierge-input"
      ],
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "ecs",
      "Targets": [
        "id=awsc-concierge-input",
        "xpath=//*[@id=\"awsc-concierge-input\"]",
        "xpath=//input[@id='awsc-concierge-input']",
        "xpath=//input[2]",
        "css=#awsc-concierge-input"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//*[@id=\"aws-unified-search-container\"]/div/div[3]/div/div/div[2]/div/div[2]/ul/li/div/div/ol/li/div/div/div[2]/div/h3/span/button",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\"aws-unified-search-container\"]/div/div[3]/div/div/div[2]/div/div[2]/ul/li/div/div/ol/li/div/div/div[2]/div/h3/span/button",
        "xpath=//span/button",
        "css=#aws-unified-search-container > div > div.search-6256.search-62577 > div > div > div.search-6241 > div > div.search-62102 > ul > li.search-62104.search-62622.search-62108 > div > div:nth-child(1) > ol > li:nth-child(1) > div > div.search-62122 > div.search-62127 > div > h3 > span > button"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//*[@id=\"view-console-home-dashboard-experience-v2_dashboard_xperience_lement-0\"]/div/div/div/div",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\"view-console-home-dashboard-experience-v2_dashboard_xperience_lement-0\"]/div/div/div/div",
        "xpath=//main/div/div[2]/div/div/div/div/div/div/div",
        "css=#view-console-home-dashboard-experience-v2_dashboard_xperience_lement-0 > div > div.awsui_root_2qdw9_1iaqz_99.awsui_root-variant-h1_2qdw9_1iaqz_150.awsui_root-has-description_2qdw9_1iaqz_141 > div > div.awsui_title_2qdw9_1iaqz_216.awsui_title-variant-h1_2qdw9_1iaqz_221"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=awsc-concierge-input",
      "Value": "",
      "Targets": [
        "id=awsc-concierge-input",
        "xpath=//*[@id=\"awsc-concierge-input\"]",
        "xpath=//input[@id='awsc-concierge-input']",
        "xpath=//input[2]",
        "css=#awsc-concierge-input"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=awsc-concierge-input",
      "Value": "",
      "Targets": [
        "id=awsc-concierge-input",
        "xpath=//*[@id=\"awsc-concierge-input\"]",
        "xpath=//input[@id='awsc-concierge-input']",
        "xpath=//input[2]",
        "css=#awsc-concierge-input"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=awsc-concierge-input",
      "Value": "",
      "Targets": [
        "id=awsc-concierge-input",
        "xpath=//*[@id=\"awsc-concierge-input\"]",
        "xpath=//input[@id='awsc-concierge-input']",
        "xpath=//input[2]",
        "css=#awsc-concierge-input"
      ],
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "cloudf",
      "Targets": [
        "id=awsc-concierge-input",
        "xpath=//*[@id=\"awsc-concierge-input\"]",
        "xpath=//input[@id='awsc-concierge-input']",
        "xpath=//input[2]",
        "css=#awsc-concierge-input"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//*[@id=\"aws-unified-search-container\"]/div/div[3]/div/div/div[2]/div/div[2]/ul/li/div/div/ol/li[2]/div/div/div[2]/div/h3/span/button",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\"aws-unified-search-container\"]/div/div[3]/div/div/div[2]/div/div[2]/ul/li/div/div/ol/li[2]/div/div/div[2]/div/h3/span/button",
        "xpath=//li[2]/div/div/div[2]/div/h3/span/button",
        "css=#aws-unified-search-container > div > div.search-6256.search-62879 > div > div > div.search-6241 > div > div.search-62102 > ul > li.search-62104.search-621051.search-62108 > div > div:nth-child(1) > ol > li:nth-child(2) > div > div.search-62122 > div.search-62127 > div > h3 > span > button"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//*[@id=\"app\"]/div/div/div/main/div/div[2]/div",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\"app\"]/div/div/div/main/div/div[2]/div",
        "xpath=//main/div/div[2]/div",
        "css=#app > div > div > div > main > div > div.awsui_content-wrapper_zycdx_1sc8d_103 > div"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=awsc-concierge-input",
      "Value": "",
      "Targets": [
        "id=awsc-concierge-input",
        "xpath=//*[@id=\"awsc-concierge-input\"]",
        "xpath=//input[@id='awsc-concierge-input']",
        "xpath=//input[2]",
        "css=#awsc-concierge-input"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=awsc-concierge-input",
      "Value": "",
      "Targets": [
        "id=awsc-concierge-input",
        "xpath=//*[@id=\"awsc-concierge-input\"]",
        "xpath=//input[@id='awsc-concierge-input']",
        "xpath=//input[2]",
        "css=#awsc-concierge-input"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=awsc-concierge-input",
      "Value": "",
      "Targets": [
        "id=awsc-concierge-input",
        "xpath=//*[@id=\"awsc-concierge-input\"]",
        "xpath=//input[@id='awsc-concierge-input']",
        "xpath=//input[2]",
        "css=#awsc-concierge-input"
      ],
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "cloudwatch",
      "Targets": [
        "id=awsc-concierge-input",
        "xpath=//*[@id=\"awsc-concierge-input\"]",
        "xpath=//input[@id='awsc-concierge-input']",
        "xpath=//input[2]",
        "css=#awsc-concierge-input"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//*[@id=\"aws-unified-search-container\"]/div/div[3]/div/div/div[2]/div/div[2]/ul/li/div/div/ol/li/div/div/div[2]/div/h3/span/button",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\"aws-unified-search-container\"]/div/div[3]/div/div/div[2]/div/div[2]/ul/li/div/div/ol/li/div/div/div[2]/div/h3/span/button",
        "xpath=//span/button",
        "css=#aws-unified-search-container > div > div.search-6256.search-621298 > div > div > div.search-6241 > div > div.search-62102 > ul > li.search-62104.search-621581.search-62108 > div > div:nth-child(1) > ol > li:nth-child(1) > div > div.search-62122 > div.search-62127 > div > h3 > span > button"
      ],
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//*[@id=\"app\"]/div/div/div/main/div/div[2]/div",
      "Value": "",
      "Targets": [
        "xpath=//*[@id=\"app\"]/div/div/div/main/div/div[2]/div",
        "xpath=//main/div/div[2]/div",
        "css=#app > div > div > div > main > div > div.awsui_content-wrapper_zycdx_1sc8d_103 > div"
      ],
      "Description": ""
    }
  ]
}

基本的には、HTMLのid属性など固定値を指定できるものはこちらを指定して、id属性がなかったり動的に表記が変わる要素は xpath を指定して操作するのが良いかと思います。

id属性はChromeの開発者ツールのセレクトモードで要素を選択することで確認することができます。

xpathは XPath Helper という拡張機能で取得するのが簡単で便利です。

XPath Helperをインストールし起動したら、Shift キーを押しながら要素を選択すると、その要素のxpathが取得できます。

これらの方法で設定したのが最初に掲載したコードになります。

(再掲)UI.Visionのソースコード
{
  "Name": "AWS Console Settings",
  "CreationDate": "2024-6-10",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://ap-northeast-1.console.aws.amazon.com/settings/home?region=ap-northeast-1",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "comment",
      "Target": "click // //button[contains(@class, 'awsui_button') and contains(@class, 'awsui_variant-primary')]",
      "Value": "",
      "Description": "リセット操作"
    },
    {
      "Command": "clickAndWait",
      "Target": "//button[@data-testid='reset-all-settings-modal-submit']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": "https://ap-northeast-1.console.aws.amazon.com/settings/display/edit?region=ap-northeast-1",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=theme-selector-light-theme-option",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=favorite-service-display-service-icon-only",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=favorites-bar-icon-size-large",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='submit-button']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": "https://ap-northeast-1.console.aws.amazon.com/settings/localization/edit",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=formField:r7:",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=option-list:r9:-option-6",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=formField:rj:",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=option-list:rl:-option-10",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "clickAndWait",
      "Target": "//button[@data-testid='submit-button']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": "https://ap-northeast-1.console.aws.amazon.com/console/home?region=ap-northeast-1",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "ec2",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-ec2']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "ecs",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-ecs']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "rds",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-rds']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "cloudformation",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-cfo']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "cloudwatch",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-cw']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "s3",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-s3']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "security hub",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-securityhub']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "guardduty",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-guardduty']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "id=awsc-concierge-input",
      "Value": "detective",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//button[@data-testid='service-list-item-toggle-favorite-button-detective']",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "//*[@id='aws-unified-search-container']/div/div[1]/button",
      "Value": "",
      "Description": ""
    }
  ]
}

こちらのコードは Import JSON or ZIP からコードをインポートすることができるので、ぜひお試しください。

他に選択しそうなコマンドメモ

個人的に利用しそうな設定要素の情報をメモしておきます!

ビジュアルモード「ダークテーマ」

    {
      "Command": "click",
      "Target": "id=theme-selector-dark-theme-option",
      "Value": "",
      "Description": ""
    },

お気に入りバー「サービス名とアイコン」

    {
      "Command": "click",
      "Target": "id=favorite-service-display-service-name-and-icon",
      "Value": "",
      "Description": ""
    },

お気に入りバーのアイコンサイズ「小」

    {
      "Command": "click",
      "Target": "id=favorites-bar-icon-size-small",
      "Value": "",
      "Description": ""
    },

言語「英語」

    {
      "Command": "click",
      "Target": "id=formField:r7:",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=option-list:r9:-option-1",
      "Value": "",
      "Description": ""
    },

デフォルトのリージョン「米国東部(バージニア北部)us-east-1」

    {
      "Command": "click",
      "Target": "id=formField:rj:",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "id=option-list:rl:-option-1",
      "Value": "",
      "Description": ""
    },

最後に

今回は、UI.Visionを使ってAWSコンソール設定の自動化を行いました。

コンソール設定のようなものはAPIが提供されていないので、こういったRPAツールを使って自動化するのも一案かと思います。

トップページのウィジェット設定までは自動化していないですが、UI.Visionの他のコマンドを利用することでこのあたりも自動化することができるかと思います。

普段、ウィジェットのカスタマイズはあまりしないので今回の検証では試していないですが、このあたりもニーズがあれば自動化してみたいなと思います。

こちらの内容がどなたかのお役に立てれば幸いです。

以上、たかやま(@nyan_kotaroo)でした。

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.